import { createWebHistory, createRouter } from 'vue-router'
import Cookies from "js-cookie";
const routes = [
    {
        path:'/',
        name:'home',
        redirect:'/index',
        component: ()=> import("@/components/Home.vue"),
        meta:{requireAuth: true},
        children:[
            {
                path:'/index',
                name:'index',
                component: ()=> import("@/components/md/Index.vue"),
            },
            // 枪神纪路由
            {
                path:'/gunz2',
                name:'gunz2',
                component: ()=> import("@/components/md/GameHome.vue")
            },
            // 角色三级菜单
            {
                path:'/gunz2/characters',
                name:'characters',
                component: ()=> import("@/components/md/CategoryList.vue")
            },
            // 武器三级菜单
            {
                path:'/gunz2/weapons',
                name:'weapons',
                component: ()=> import("@/components/md/CategoryList.vue")
            },
            // 角色四级菜单 - 阵营
            {
                path:'/gunz2/characters/vampire',
                name:'vampire',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/characters/judge',
                name:'judge',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/characters/agent',
                name:'agent',
                component: ()=> import("@/components/md/ProfessionList.vue")
            },
            // 武器四级菜单 - 职业
            {
                path:'/gunz2/weapons/blade_point',
                name:'weaponBladePoint',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/weapons/flame',
                name:'weaponFlame',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/weapons/double_gun',
                name:'weaponDoubleGun',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/weapons/machine_gun',
                name:'weaponMachineGun',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/weapons/guided_missile',
                name:'weaponGuidedMissile',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/weapons/sniper',
                name:'weaponSniper',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/weapons/medic',
                name:'weaponMedic',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/weapons/grenade',
                name:'weaponGrenade',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/weapons/engineer',
                name:'weaponEngineer',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            // 特工五级菜单 - 职业
            {
                path:'/gunz2/characters/agent/blade_point',
                name:'agentBladePoint',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/characters/agent/flame',
                name:'agentFlame',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/characters/agent/double_gun',
                name:'agentDoubleGun',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/characters/agent/machine_gun',
                name:'agentMachineGun',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/characters/agent/guided_missile',
                name:'agentGuidedMissile',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/characters/agent/sniper',
                name:'agentSniper',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/characters/agent/medic',
                name:'agentMedic',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/characters/agent/grenade',
                name:'agentGrenade',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            {
                path:'/gunz2/characters/agent/engineer',
                name:'agentEngineer',
                component: ()=> import("@/components/md/ModelList.vue")
            },
            // 其他游戏路由（敬请期待）
            {
                path:'/honor_of_kings',
                name:'honorOfKings',
                component: ()=> import("@/components/md/ComingSoon.vue")
            },
            {
                path:'/pubg_mobile',
                name:'pubgMobile',
                component: ()=> import("@/components/md/ComingSoon.vue")
            },
            {
                path:'/genshin_impact',
                name:'genshinImpact',
                component: ()=> import("@/components/md/ComingSoon.vue")
            },
            {
                path:'/league_of_legends',
                name:'leagueOfLegends',
                component: ()=> import("@/components/md/ComingSoon.vue")
            },
            {
                path:'/valorant',
                name:'valorant',
                component: ()=> import("@/components/md/ComingSoon.vue")
            },
            {
                path:'/overwatch',
                name:'overwatch',
                component: ()=> import("@/components/md/ComingSoon.vue")
            },
            {
                path:'/apex_legends',
                name:'apexLegends',
                component: ()=> import("@/components/md/ComingSoon.vue")
            },
            {
                path:'/fortnite',
                name:'fortnite',
                component: ()=> import("@/components/md/ComingSoon.vue")
            }
        ]
    },
    {
        path: '/login',
        name: 'login',
        component: ()=> import("@/components/Login.vue")
        //component: ()=> import("@/components/RAL.vue")
    },
    {
        path: '/register',
        name: 'register',
        component: ()=> import("@/components/Register.vue")
        //component: ()=> import("@/components/RAL.vue")
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})
router.beforeEach((to, from, next) => {
    if (to.meta.requireAuth) {
        const token = Cookies.get('token');
        if (token) {
            next();
        } else {
            next({
                path: '/login',
                query: { redirect: to.fullPath }
            });
        }
    } else {
        next();
    }
});


export default router;